package com.example.car.service.Impl;

import com.example.car.entity.Car;
import com.example.car.entity.Order;
import com.example.car.mapper.CarMapper;
import com.example.car.params.CarParams;
import com.example.car.service.CarService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarServiceImpl implements CarService {

    @Autowired
    private CarMapper carMapper;

    @Override
    public List<Car> getCarList(CarParams carParams) {

//        Criteria criteria = new Criteria();
//
//        String carName = carParams.getCarName();
//        if(!StringUtils.isBlank(carName)) {
//            criteria.where("name").regex(".*?\\" + carParams + ".*");
//        }
//
//        String type = carParams.getType();
//        if(!StringUtils.isBlank(type)) {
//            criteria.where("type").is(type);
//        }
//
//        Integer status = carParams.getStatus();
//        if(status != null ) {
//            criteria.where("type").is(type);
//        }

        List<Car> list = carMapper.getCarList(carParams.getPage(), carParams.getLimit());
        return list;
    }

    @Override
    public Car getCarById(String carId) {
        return carMapper.getCarById(carId);
    }

    @Override
    public void rentCar(String carId) {
        carMapper.rentCar(carId);
    }
}
